x
breed [particles particle]breed [ion-channels ion-channel]particles-own [my-position charge]to setup clear-all ; add sodium ions inside ask patches with [pxcor < -2] [ if random 100 < 10 [ sprout-particles 1 [ set shape "circle" set size 0.5 set color red fd random-float 1 set my-position "inside" set charge "positive" ] ] ] ; add sodium ions outside ask patches with [pxcor > 2] [ if random 100 < 98 [ sprout-particles 1 [ set shape "circle" set size 0.5 set color red fd random-float 1 set my-position "outside" set charge "positive" ] ] ] ; add chloride ions inside ask patches with [pxcor < -2] [ if random 100 < 9 [ sprout-particles 1 [ set shape "circle" set size 0.5 set color green fd random-float 1 set my-position "inside" set charge "negative" ] ] ] ; add chloride ions outside ask patches with [pxcor > 2] [ if random 100 < 100 [ sprout-particles 1 [ set shape "circle" set size 0.5 set color green fd random-float 1 set my-position "outside" set charge "negative" ] ] ] ; add potassium ions inside ask patches with [pxcor < -2] [ if random 100 < 83 [ sprout-particles 1 [ set shape "circle" set size 0.5 set color yellow fd random-float 1 set my-position "inside" set charge "positive" ] ] ] ; add potassium ions outside ask patches with [pxcor > 2] [ if random 100 < 3 [ sprout-particles 1 [ set shape "circle" set size 0.5 set color yellow fd random-float 1 set my-position "outside" set charge "positive" ] ] ] ; make chambers ask patches with [pxcor < 2 and pxcor > -2] [set pcolor blue] reset-ticksendto random-walk ; take a step forward through fractional distance less than 1 fd random-float 1 ;randomize direction (heading) for the next step rt random 360endto go ifelse trace-path? [ ask turtles [pen-down] ] [ ask turtles [pen-up] ] ask turtles [ ; if you are near a blue wall or an edge , turn back, else do the random walk if my-position = "inside" [ if patch-ahead 1 = nobody [ set heading 90 fd 1 ] if [pcolor] of patch-ahead 1 = blue [ set heading 270 fd 1 ] ] if my-position = "outside" [ if patch-ahead 1 = nobody [ set heading 270 fd 1 ] if [pcolor] of patch-ahead 1 = blue [ set heading 90 fd 1 ] ] random-walk ; additional movement because of the charges if strength-of-the-field > 0 [ if charge = "positive" [ if (xcor + strength-of-the-field) < max-pxcor [ ; to make sure that the particle does not move beyod the edge of the world set xcor (xcor + strength-of-the-field) ] ] if charge = "negative" [ if (xcor - strength-of-the-field) > min-pxcor [ ; to make sure that the particle does not move beyod the edge of the world set xcor (xcor - strength-of-the-field) ] ] ] if strength-of-the-field < 0 [ if charge = "positive" [ if (xcor + strength-of-the-field) > min-pxcor [ ; to make sure that the particle does not move beyod the edge of the world set xcor (xcor + strength-of-the-field) ] ] if charge = "negative" [ if (xcor - strength-of-the-field) < max-pxcor [ ; to make sure that the particle does not move beyod the edge of the world set xcor (xcor - strength-of-the-field) ] ] ] ] tickend